package com.pai4j.pgc.dao.community;
import com.pai4j.pgc.entity.community.CCExperienceEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 *
 * @author: CYM-pai
 * @date: 2025/10/27 14:38
 **/
@Repository
public interface ICCExperienceEntityDAO extends JpaSpecificationExecutor<CCExperienceEntity>,
                                                JpaRepository<CCExperienceEntity, Long> {


    @Transactional
    @Modifying
    @Query("update CCExperienceEntity e set e.viewCount = e.viewCount + 1 where e.id = ?1")
    int increxExperienceViewCount(Long experienceId);

    List<CCExperienceEntity> findAllByPathIdAndStatusOrderByIdDesc(Long pathId, String status);

    List<CCExperienceEntity> findAllByStatusAndPathIdIn(String status, List<Long> pathIdList);

    List<CCExperienceEntity> findAllByPathIdAndRecommendAndStatusOrderByIdDesc(Long pathId, Boolean recommend, String status);
    List<CCExperienceEntity> findAllByPathIdAndTopAndStatusOrderByIdDesc(Long pathId, Boolean top, String status);


    @Query(value = "select signs from pai4j_experience where path_id = :pathId and signs is not null order by create_date desc limit 100",
            nativeQuery = true)
    List<String> findAllSignsLimit100ByPathId(Long pathId);
}
